<?php

/**
 * CRUD module bootstrap
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: Bootstrap.php 38 2009-02-18 17:12:39Z monzee $
 */
class Crud_Bootstrap extends Mz_Module_Bootstrap
{

    public function init()
    {
        $vr = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $vr->initView();

        $view = $vr->view;
        $view->addHelperPath(self::pathTo('/views/helpers'), 'Crud');
    }

    public function getAdapter()
    {
        $default = Zend_Db_Table_Abstract::getDefaultAdapter();

        $iniFile = $this->pathTo('config.ini');

        if (!file_exists($iniFile)) {
            return $default;
        }

        $config = new Zend_Config_Ini($iniFile, 'crud');
        $config = $config->db->toArray();
        if (empty($config)) {
            return $default;
        }

        return Zend_Db::factory($config['adapter'], $config['params']);
    }


}